<?php

/**
 * 商标管理系统 v1.0.1
 *
 * 商业运营到ubtm.cn官网进行授权使用。
 *
 * (c) cighsen02 <xiayu@959602.com>
 *
 * Create at：2025.05.01
*/

namespace App\Services\Auth;

use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;

/**
 * 用户验证类
 */
class ValidatorUser
{
    /**
    * 用户注册
    *
    * @param array $data
    * @throws ValidationException
    * @return array
    */
    public function register(array $data): array
    {
        $validator = Validator::make($data, [
            'name' => 'required|string|max:255',
            'email' => 'required|email|unique:users,email',
            'password' => 'required|string|min:6|confirmed'
        ]);

        if ($validator->fails()) {
            throw new ValidationException($validator);
        }

        return $validator->validated();
    }

    /**
    * 用户登陆
    *
    * @param array $data
    * @throws ValidationException
    * @return array
    */
    public function login(array $data): array
    {
        $validator = Validator::make($data, [
            'email' => 'required|email',
            'password' => 'required|string',
        ]);

        if ($validator->fails()) {
            throw new ValidationException($validator);
        }

        return $validator->validated();
    }
}
